//
//  RouteListTableViewCell.m
//  TravelFirst
//
//  Created by lanou3g on 15/9/21.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "RouteListTableViewCell.h"

@implementation RouteListTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
        if(self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]){
            self.selectionStyle=0;
            _img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 5, kWidth-20, 190)];
            [self addSubview:_img];
            UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(70, 70, _img.frame.size.width-140, _img.frame.size.height-140)];
            [lab setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_top_320x64@2x"]]];
            [_img addSubview:lab];
            UILabel *laba=[[UILabel alloc]initWithFrame:CGRectMake(70, 70+lab.frame.size.height, _img.frame.size.width-140,1)];
            laba.backgroundColor=[UIColor whiteColor];
            [_img addSubview:laba];
            _name=[[UILabel alloc]initWithFrame:CGRectMake(_img.frame.size.width/2-50, lab.frame.size.height+20, 100, 30)];
            
            _name.textAlignment=1;
            _name.textColor=[UIColor whiteColor];
            [_img addSubview:_name];
            _city=[[UILabel alloc]initWithFrame:CGRectMake(_img.frame.size.width/2-70, lab.frame.size.height+50, 140, 10)];
            _city.textAlignment=1;
            _city.textColor=[UIColor whiteColor];
            _city.font=[UIFont boldSystemFontOfSize:12];
            [_img addSubview:_city];
        }
        return self;
}

-(void)setModelvalue:(RouteListModel *)model{
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.cover]];
    self.name.text=model.name;
    self.city.text=model.destination;
    if(model.is_new==1){
        
        UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        img.image=[UIImage imageNamed:@"img_new_route_40x40@2x"];
        [self.img addSubview:img];
    }
    //居中心心
    int t=floor(model.trail_score);
    CGFloat w = self.img.frame.size.width/2-((t+1)/2)*15;
    for(int i=1;i<=t;i++){
        if(i%2==0){
            UIImageView *imgs=[[UIImageView alloc]initWithFrame:CGRectMake(i*10+w, 130, 20, 20)];
            imgs.image=[UIImage imageNamed:@"img_star_18x18@2x"];
            [self.img addSubview:imgs];
        }
        if(i==t && t%2==1){
            UIImageView *imgs=[[UIImageView alloc]initWithFrame:CGRectMake(i*10+w+10, 130, 20, 20)];
            imgs.image=[UIImage imageNamed:@"img_star_half_18x18@2x"];
            [self.img addSubview:imgs];
        }
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
